package shoooter.entity.nonimage.enemy;

import shoooter.geometry.Vec2;
import java.awt.*;
import shoooter.entity.BasicGameEntity;
import shoooter.entity.nonimage.NonImageEntity;
import shoooter.entity.nonimage.Projectile;


public class Enemy extends NonImageEntity {

    /* radius of the circle */
    public int radi;
    public int hp;
    int points;
    public int rad;
    public static int SPEED = 3;

 /*   public Enemy() {
        super();
        this.hp = 0;
        this.points = 0;
    }*/

     public Enemy(int x, int y, int hp, int score, int rad, Color c) {
        super();
        this.radi = rad;
        this.vPos.setX(x);
        this.vPos.setY(y);
        this.setColor(c);
        this.setBordercolor(Color.black);
        this.hp = hp;
        this.points = score;
    }

    public void hit(int damage) { this.hp -= damage; };

    
    public int getScore() {
        return this.points;
    };

    @Override
    public boolean isAlive() { return (this.hp > 0); }


    public void moveToward(int x, int y) {

        double radiant = Math.atan2(y - this.vPos.getY(), x - this.vPos.getX());
        Vec2 myV = Vec2.nullVec2();

        myV.setX(SPEED*Math.cos(radiant));
        myV.setY(SPEED*Math.sin(radiant));

        this.setvSpe(myV);
        this.move();
    }

    public void moveToward(BasicGameEntity target) {

        double radiant = Math.atan2(target.vPos.getY() - this.vPos.getY(), target.vPos.getX() - this.vPos.getX());
        Vec2 myV = new Vec2(getX(), getY());

        myV.setX(SPEED*Math.cos(radiant));
        myV.setY(SPEED*Math.sin(radiant));

        this.setvSpe(myV);
        this.move();
    }
    
    
    public void draw(Graphics2D g2d) {
        g2d.setColor(this.getColor());
        g2d.fillOval((int) this.getX() - this.radi, (int) this.getY() -this.radi, this.radi*2, this.radi*2);
        g2d.setColor(this.getBordercolor());
        g2d.drawOval((int) this.getX() - this.radi, (int) this.getY() -this.radi, this.radi*2, this.radi*2);
    }
    

    public boolean hitten(Projectile p) {

        if(Vec2.distance(this.vPos, p.vPos) <=  this.radi)
            return true;
        else
            return false;
    }


    public boolean die() {
        return ( this.hp <= 0 );
    }
    
    public void attack() {

    }
}
